// index.js
Page({
  data:{
    array1:["小王，你好dfasdfasdfasdafsdfasdsfdsggfsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdf","小李，你好dfasdfasdfasdfasdfasdfagdsfgsdfgsdfgfsdgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdf","alice,hellodsfadfasdfasdfasdrfasdffgsdfsdfgsdfgdsfgdfsfdfgdsf"],
    array: ['这是第一条消息，它会从右向左滚动', '这是第二条消息，稍微长一些以便测试效果', '第三条消息来啦，看看效果如何？'],
    message:"这是第一条消息，它会从右向左滚动.这是第二条消息，稍微长一些以便测试效,第三条消息来啦，看看效果如何?",
    duration: 15 , // 默认动画持续时间，单位秒
    userInfo:{
        userName:"小王",
        score:"98",
        symbolnumerical:"+" 
    },
    topScores: [
      {
        scorerName: "张三",
        scorerAvatar: "./image/avator.webp",
        deductorName: "李四",
        deductorAvatar: "./image/WeuiAddOutlined.webp",
        score: 100
      },
      {
        scorerName: "王五",
        scorerAvatar: "./image/avator.webp",
        deductorName: "赵六",
        deductorAvatar: "./image/WeuiAddOutlined.webp",
        score: 80
      }
    ],
    roomId: '',
    inviteLink: ''
  },
  onLoad: function(options) {
    const roomId = options.roomId;
    this.setData({ 
      roomId: roomId,
      inviteLink: `https://your-miniapp.com/room?roomId=${roomId}`
    });
    this.calculateDuration();
  },
  calculateDuration: function() {
      // 根据文字长度计算动画持续时间
      const messageLength = this.data.message.length;
      const duration = messageLength * 0.3;  // 可以调整这个系数来改变速度
      this.setData({ duration: duration });
    },
  onShareAppMessage: function() {
    return {
      title: '加入我的虚拟房间',
      path: `/pages/room/room?roomId=${this.data.roomId}`,
      imageUrl: '/images/room-share.png'
    }
  },
  
  createRoom: function() {
    wx.request({
      url: 'https://your-api.com/create-room',
      method: 'POST',
      data: {
        userId: wx.getStorageSync('userId'),
        // 其他房间信息
      },
      success: (res) => {
        const roomId = res.data.roomId;
        this.setData({ roomId: roomId });
        // 跳转到房间页面
        wx.navigateTo({
          url: `/pages/room/room?roomId=${roomId}`
        });
      }
    });
  },
  chooseContact: function() {
    wx.chooseContact({
      success: function(res) {
        console.log('选中的联系人：', res.phoneNumber, res.displayName)
        // 这里可以处理选中的联系人信息
      },
      fail: function(res) {
        console.log('选择联系人失败', res)
      }
    })
  },
  inviteUser:function (res) {
    chooseContact();
    return {
      title: '邀请你加入我的小程序',
      path: '/pages/index/index?inviter=123',
      imageUrl: '/images/share.png' // 可选，自定义分享图片
    }
  }
})